<?php 
$GLOBALS['Md'] = "Clients";
$GLOBALS['Pd'] = "N";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
print heade(); 
print body(); 
module($BSD['DB00']); 
office_header($_SESSION[$SESSOF]);
include($GLOBALS['PAD']."Modules/Clients/nav.views.php");
print NavFront();
?>
<div id="Centro" class="strcture">
<?php
include($GLOBALS['PAD']."Modules/Clients/main.obj.php");

if (isset($_POST['ClientSave'])) {

	if ($_POST['client_number'] != "" && $_POST['name'] != "" && $_POST['name_last'] != "" && $_POST['name_middle'] != "" && $_POST['id_number'] != "" && $_POST['id_type'] != "") {
	
	if (isset($_POST['id_last_verification'])) {
		$_POST['id_last_verification'] = $GLOBALS['T'];
		} else {
		$_POST['id_last_verification'] = '0';
		}
	
	$CSave = "INSERT INTO main_clients (client_number, client_profile_ref, name, id_type, id_number, id_last_validation, name_last, name_middle) VALUES ('{$_POST['client_number']}','{$_POST['client_profile_ref']}','{$_POST['name']}','{$_POST['id_type']}','{$_POST['id_number']}','{$_POST['id_last_verification']}','{$_POST['name_last']}','{$_POST['name_middle']}')";
	$Save = $GLOBALS['CONN']->db_query($CSave);
	print "Dados guardados com sucesso.";
	} else {
	print "Preencha todos os campos.";
	}
} else {

}

?>

<table width="100%"  border="0" cellpadding="10">
  <?php if(isset($_GET['action']) && $_GET['action'] == "new") { ?>
  <tr>
    <td><table width="100%"  border="0" cellpadding="10" cellspacing="1">
      <tr bgcolor="#009999">
        <td colspan="3">Novo Cliente </td>
      </tr>
	<?php echo Obj_Create_Client();?>
    </table> </td>
  </tr>
  <?php } ?>
  <tr>
    <td>Pesquisar cliente

			<table width="100%"  border="0" cellpadding="10" cellspacing="3">
		<form action="index.php" method="post">
        <tr bgcolor="#F2F2F2">
          <td width="80%"><div align="right">
            <input name="search_string" type="text" id="search_string" size="40">
          </div></td>
          <td width="20%">
		  <input name="Search" type="submit" id="Search" value="Pesquisar">
          </td>
		  
        </tr>
		</form>
</table></td>
  </tr>
  <?php if(isset($_POST['search_string'])) { ?>
  <tr>
    <td>Resultados para a pesquisa por &quot;
        <?php echo $_POST['search_string'];?>
  &quot;:
   <table width="100%"  border="0" cellpadding="2" cellspacing="3">
          <tr bgcolor="#009999">
            <td>N&uacute;mero</td>
            <td>Nome</td>
            <td bgcolor="#009999">Id</td>
            <td>Tipo Doc </td>
          </tr>
 	<?php 
	$QCall = "SELECT * FROM main_clients WHERE name LIKE '%{$_POST['search_string']}%' OR id_number LIKE '%{$_POST['search_string']}%'";
	$Call = $GLOBALS['CONN']->db_array($QCall);
	for ($i = 1; $i = $Call[0]; $i++) { ?>

          <tr bgcolor="#F2F2F2">
            <td width="20%"><?php echo $Call[$i]['ref'];?></td>
            <td width="40%"><?php echo $Call[$i]['name'];?></td>
            <td width="20%" bgcolor="#F2F2F2"><?php echo $Call[$i]['id_number'];?></td>
            <td width="20%"><?php echo $Call[$i]['id_type'];?></td>
        </tr>
		<?php } ?>
      </table></td>
  </tr>
  <?php } ?>
</table>
</div>
<?php print footer(); ?>